package com.john.sqwen.ecbc.core.datasource;

import com.john.sqwen.ecbc.commons.config.dataconfig.DynamicDataSourceContextHolder;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import javax.sql.DataSource;
import java.util.Map;

/**
 * @author john_sqwen
 * @packageName com.john.sqwen.ecbc.core.datasource
 * @date 2022/4/24
 * @projectName ecbc-base
 * @Description DynamicDataSource
 **/

public class DynamicDataSource extends AbstractRoutingDataSource {
    public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources)
    {
        super.setDefaultTargetDataSource(defaultTargetDataSource);
        super.setTargetDataSources(targetDataSources);
        super.afterPropertiesSet();
    }

    @Override
    protected Object determineCurrentLookupKey()
    {
        return DynamicDataSourceContextHolder.getDataSourceType();
    }
}
